// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/accesscontrol/api/AccessControlPointApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/accesscontrol/model/AccessControlPointDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.statusList)
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'accessControlPointQuery', DTO)
    return [resp.comQuery.totalCount, resp.content || [], { 5: resp.onLineCount, 4: resp.offLineCount }]
  },
  dealList([obj], { state: { MAP } }) {
    if (MAP.COUNT) MAP.COUNT = obj || {}
  },
  transList(arr) {
    arr.forEach((item) => {
      item.detailId = item.id // 详情 ID
      item.status = item.status === 4 ? 4 : 5 // 门禁点状态
      item.doorStatus = item.doorStatus || 2 // 开关门状态
    })
    return arr
  },
}
